import requests
import json


def chat(text):
    response = requests.post(url="https://api.openai.com/v1/completions",
                             data=json.dumps({
                                 "model": "text-davinci-003",
                                 "prompt": text,
                                 "max_tokens": 1000,
                                 "temperature": 0.6,
                                 "user": "598778567@qq.com"
                             }),
                             headers={
                                 'Authorization': 'Bearer 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',
                                 'Content-Type': 'application/json'
                             })
    resp = response.content
    print(resp)
    print(json.loads(resp)['choices'][0]['text'])
    return json.loads(resp)['choices'][0]['text']
